<?php

/* @project : Template
 * @auther  : 青云
 * @date    : 2018/1/10
 * @desc    : 菜单模型
 */

namespace app\common\model;

use think\Db;
use think\Model;

class SystemGroup extends Model
{
    function getGroupByCode($code)
    {
        $where[] = ['code', 'eq', $code];
        $group   = $this->where($where)->find();
        return $group;
    }

    function del($id)
    {
        // 启动事务
        Db::startTrans();
        $ret_group_data = false;
        $ret_group      = false;
        try {
            $ret_group_data = (new SystemGroupData())
                ->where('group_id', 'eq', $id)
                ->delete();
            $ret_group      = $this->where('id', $id)->delete();

            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }

        return $ret_group_data & $ret_group;
    }
}
